# --------------------------------------------------------
# ' Figure 3
# --------------------------------------------------------

library(rio)
library(data.table)
library(maps)
library(stringr)
library(hrbrthemes)
library(tidyverse)
theme_set(theme_ipsum_rc())
library(gridExtra)
library(grid)
library(ggpubr)

# specify your root directory here
here = '~/Dropbox/project-archive/BG-bk/dataverse'

# load data : state election results 
thanksgiving = data.table(import(file.path(here,'data','processed','thanksgiving2016_plot.dta')))
thanksgiving = na.omit(thanksgiving)

thanksgiving[, bg_tg := as.factor(bg_tg)]
thanksgiving[, bg_tg := factor(bg_tg, label = c("Non-close","Close"))]

p <-thanksgiving  %>% ggplot(
	aes(x=P_Diff, y=Time_At_Thanksgiving, color=bg_tg, group=bg_tg,fill=bg_tg)) +
	stat_smooth(aes(group=bg_tg, color=bg_tg, fill=bg_tg),method='lm',size=1, se = TRUE)+
	labs(x="Probability of Political Mismatch",y="Duration of Thanksgiving Dinner (min)",
		color = "State-level election results are...",
		fill =  "State-level election results are...",
		group =  "State-level election results are...") + 
	scale_color_manual(values=c('black','red'))+
	scale_fill_manual(values=c('darkgray','pink'))+
	theme(legend.position = "top") +
	theme_pubr()

ggsave(file=file.path(here,'output','figure_thanksgiving_line.png'), plot=p, width=6, height=6,dpi=1000)


